package com.yxb.config.aspect;

import com.yxb.config.rest.RestResult;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {

    private static final Logger  LOGGER  = LoggerFactory.getLogger(LogAspect.class);

    @AfterReturning(pointcut = "this(com.yxb.api.rest.HelloController)", returning = "res")
    public void logAfterReturning(JoinPoint point, ResponseEntity<RestResult> res) {
        System.out.println("afterReturning");
        String name = point.getSignature().getName();
        LOGGER.info("name:[{}]-接口返回值:{}", name, res.getBody().toString());
    }

//    @AfterReturning(pointcut = "within(com.yxb.api.rest..*) || within(com.yxb.gateway..*)", returning = "res")
//    public void logAfterReturning(JoinPoint point, ResponseEntity<RestResult> res) {
//        String name = point.getSignature().getName();
//        LOGGER.info("name:[{}]-接口返回值:{}", name, res.getBody().toString());
//    }

}
